<!DOCTYPE html> 
<html> 
<head>  <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="dashboard.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
<meta charset="utf8"/> 
<title>计算器</title> 
<style>
    .panel{
        width: 400px;
        height: 500px;
        margin: 10px 500px;}
        #show{
            BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid #c0c0cc;
            position: absolute;
            margin-top: -40px;
        }
</style></head> 
<body> 
    <div class="panel panel-default">
        <div class="panel-heading">
            简易计算器
        </div>
    <div class="panel-body" style="padding: 80px 80px;" >
    <table> 
<tr> 
<td colspan="4"><input id="show" value="0"/></td> 
</tr> 
<tr> 
    <div class="container"><div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button"style="width: 60px;height:60px ;" onclick="number(this)" value="7">7</button></td> </div>
    <div class=".col-xs-3"><td><button  class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="8">8</button></td> </div>
        <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="9">9</button></td> </div>
            <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="calsym(this)" value="+">+</button></td> </div>
</tr> 
<tr> 
    <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="4">4</button></td> </div>
        <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="5">5</button></td> </div>
            <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="6">6</button></td> </div>
                <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="calsym(this)" value="-">-</button></td> </div>
</tr> 
<tr> 
    <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="1">1</button></td> </div>
        <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="2">2</button></td> </div>
            <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="3">3</button></td> </div>
                <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="calsym(this)" value="*">*</button></td> </div>
</tr> 
<tr> 
    <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="number(this)" value="0">0</button></td> </div>
        <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="calsym(this)" value="=">=</button></td> </div>
            <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="clearCal()" value="c">c</button></td> </div>
                <div class=".col-xs-3"><td><button class="btn btn-default btn-lg" type="button" style="width: 60px;height:60px ;" onclick="calsym(this)" value="/">/</button></td> </div>
</tr></div> 
</table> </div>
<div class="panel-footer" style="margin-top:20px;">@2019 Doyle</div>
                    </div>
</body> 
<script type="text/javascript" src="jquery-1.9.1.js"></script> 
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script> 
<script type="text/javascript"> 
var num0 = null; 
var num1 = null; 
var symble = null; 
var lastclick = null; 
var symarr = new Array(); //符号集合 
symarr[0] = '+'; 
symarr[1] = '/'; 
symarr[2] = '*'; 
symarr[3] = '-'; 
symarr[4] = '='; 
function number(n){ 
var numnow = $('#show'); 
var _exist=$.inArray(lastclick,symarr); //判断上次点击是否为符号 
if (numnow.val() == 0 || _exist != -1) {//若显示框为0 或者上次点击为符号，则重新记录显示框 
numnow.val($(n).val()); 
}else{ 
numnow.val(parseInt(numnow.val()) * 10 +parseInt($(n).val())); 
} 
lastclick = $(n).val(); // 更新上次点击 
} 
 
function calsym(cs){ //符号点击事件响应 
var numnow = $('#show'); 
var _exist=$.inArray(lastclick,symarr); 
if (num0 == null && symble == null) { //初始状态 
num0 = numnow.val(); 
symble = $(cs).val(); 
}else if(num0 != null && num1 == null && _exist !=-1){ // 连续点操作符的处理，及第一次点击操作符处理 
symble = $(cs).val(); 
}else{ //正常计算状态 
num1 = numnow.val(); 
var result = calculate(symble,num0,num1); 
symble = $(cs).val(); //上行及本行：先计算之前的运算符及结果，再更新运算符为本次点击 
num0 = result; 
numnow.val(result); 
num1 = null; 
} 
lastclick = $(cs).val(); // 更新上次点击 
} 
 
function clearCal(){ //清空函数 
$('#show').val('0'); 
num0 = null; 
num1 = null; 
symble = null; 
lastclick = null; 
} 
 
function calculate(sym,m,n){ //计算并返回结果 
var res = null; 
m = parseInt(m); 
n = parseInt(n); 
switch(sym){ 
case '+': 
res = m+n; 
break; 
case '-': 
res = m-n; 
break; 
case '*': 
res = m*n; 
break; 
case '/': 
if (n == 0) { 
alert("false"); 
break; 
} 
res = m/n; 
break; 
default: 
break; 
} 
return res; 
} 
</script> 
</html>